﻿using Npgsql;
using Real.Datos.Interfaces;
using Real.Entidad;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using Dapper;
using DapperExtensions;

namespace Real.Datos.Repositories
{
    public interface IMarcaRepository : IRepository<Marca>
    {
        IList<Marca> FindByIdProveedor(int proveedor_id);

    }
    public class MarcaRepository : IMarcaRepository
    {
        protected readonly IDbConnection _db;

        public MarcaRepository()
        {
            _db = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["REAL"].ToString()); 
        }

        public IList<Marca> FindAll()
        {
            using (IDbConnection _db = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["REAL"].ToString()))
            {
                return _db.Query<Marca>("SELECT * FROM MARCA").ToList();
            }         
        }

        public IList<Marca> Find(System.Linq.Expressions.Expression<Func<Marca, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public Marca FindById(int id)
        {
            throw new NotImplementedException();
        }

        public int Add(Marca newEntity)
        {
            throw new NotImplementedException();
        }

        public bool Remove(int id)
        {
            throw new NotImplementedException();
        }

        public int Modify(Marca entity)
        {
            throw new NotImplementedException();
        }

        public IList<Marca> FindByIdProveedor(int proveedor_id)
        {
            string query = "SELECT * FROM MARCA WHERE PROID = " + proveedor_id; 

            using (IDbConnection _db = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["REAL"].ToString()))
            {
                return _db.Query<Marca>(query).ToList();
            }        
        }
    }
}
